%{
#include <stdio.h>
%}

%union{
   int value; 
   char *ident;
}

%token IDENT
%token NUMBER
%token ASSIGNOP
%token DEFINE
%token IF
%token THEN
%token ELSE
%token FI
%token WHILE
%token DO
%token OD
%token PROC
%token END

%%


program:
	stmt_list
	{printf("[PASS]\n"); }
;

stmt_list:
	stmt ';' stmt_list 
	{ }
	|
	stmt
	{ }
;

stmt:
	assign_stmt
	{ }
	|
	define_stmt
	{ }
	|
	if_stmt
	{ }
	|
	while_stmt
	{ }
;

mixed:
	expr
	{ }
	|
	proc
	{ }
;

assign_stmt:
	IDENT ASSIGNOP mixed
	{ }
;


bracketed_param_list: 
	'(' param_list ')' 
	{ }
	|
	'(' ')'
	{ }
;

define_stmt:
	DEFINE IDENT proc
	{ }
;

if_stmt: 
	IF expr THEN stmt_list ELSE stmt_list FI
	{ }
;

while_stmt:
	WHILE expr DO stmt_list OD
	{ }
;

param_list:
	IDENT ',' param_list 
	{ }
	|
	IDENT
	{ }
;

expr:
	expr '+' term
	{ }
	|
	expr '-' term
	{ }
	|
	term
	{ }
;

term:
	term '*' factor
	{ }
	|
	factor
	{ }
;

factor:
	'(' expr ')'
	{ }
	|
	NUMBER
	{ }
	|
	IDENT
	{ }
	|
	funcall
	{ }
;

operator:
	'+'
	{ }
	|
	'-'
	{ }
	|
	'*'
	{ }
;
	
argument:
	'(' ')'
	{ }
	|
	'(' mixed_list ')'
	{ }
;
		
funcall:
	proc argument
	{ }
	|
	funcall argument
	{ } 
	|
	IDENT argument 
	{ }
;

mixed_list:
	mixed ',' mixed_list
	{ }
	|
	mixed
	{ }
;
	
proc:
	PROC bracketed_param_list stmt_list END
	{ }
	|
	operator
	{ }
;	
%%

main(int argc, char **argv)
{
	yyparse();
}

yyerror(char* s)
{
	fprintf(stderr, "[FAIL] error: %s\n", s);
} 